package com.xgq.drink.controller;

import com.xgq.drink.entity.R;
import com.xgq.drink.entity.UserBehavior;
import com.xgq.drink.service.IUserBehaviorService;
import com.xgq.drink.utils.JwtTokenUtil;
import com.xgq.drink.utils.RUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户行为表 前端控制器
 * </p>
 *
 * @author xgq
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/userBehavior")
@Tag(name = "用户行为模块", description = "用户行为相关接口")
public class UserBehaviorController {
    @Autowired
    private IUserBehaviorService userBehaviorService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @PostMapping("/add")
    @Operation(summary = "添加用户行为", description = "添加用户行为")
    public R addBehavior(@RequestBody UserBehavior userBehavior, HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        Long userId = Long.parseLong(jwtTokenUtil.getUserIdFromToken(token));
        userBehavior.setUserId(userId);
        boolean result = userBehaviorService.save(userBehavior);
        return result ? RUtils.success("OK") : RUtils.fail("NO");
    }
}
